doukuang1897 2014-09-24 16:56
浏览 28
已采纳

从朋友服务器转移到MAMP后重新链接PHP,修复HTML或PHP?

I had a friend help me with some database work and he even made a basic html display of the functions...

I am now trying to move those functions to let us mess around with displays here at work.

The first drop down will load just fine, but the second and third ones are not loading.

I have the php database files loaded to the MySQL admin part in my MAMP server, but still can't get the code to reference it.

Is this something I can fix in HTML or PHP?

 
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>dynaflex products testing</title>
<SCRIPT language=JavaScript>
function reload(form) //this js function fires when the 1st dropdown box is changed
{
var val=form.Makerid.options[form.Makerid.options.selectedIndex].value; //takes the "value" from the options listed in the form
self.location='dd3.php?id='+val ;//changes the location ofthe page (redirect) but it is taking the value from the above line
}
function reload3(form)//this function fires when u select the 2nd dropdown, it allows u to select from the 3rd box
{

var val=form.Makerid.options[form.Makerid.options.selectedIndex].value; //takes value from the 1st box
var val2=form.theModels.options[form.theModels.options.selectedIndex].value;  //takes value from the 2nd box
self.location='dd3.php?id=' + val + '&id3=' + val2 ;//this then redirects taking with it the values from above just like the last function but has 1 more varible
}
function redirect(form)//this form is the last box's action, can only be fired when u select the 3rd box
{
    self.location=form.theYears.options[form.theYears.options.selectedIndex].value; //redirects you to the url inside of the table at the url/value field just like the 1st function but differnt
}
</script>
</head>

<body>
<form method=post name=f1 action='../../../Users/Marketing/Desktop/dd3ck.php'><select name='Makerid' onchange="reload(this.form)"><option value=''>Select one</option><option value=1>Peterbilt</option><option value=2>Kenworth</option><option value=3>Western Star</option><option value=4>Freightliner</option></select></form><br><br>
<a href=../../../Users/Marketing/Desktop/dd3.php>Reset and Try again</a>
<br><br>
</body>
</html>


dd3ck.php (PHP Code, as pasted into comment below gibberish's answer):

<!doctype html public "-//w3c//dtd html 3.2//en"> 
<html> 
    <head> 
        <title>Multiple drop down list box from plus2net</title> 
    </head> 

    <body> 

    <?Php 
        $cat=$_POST['cat']; 
        $subcat=$_POST['subcat']; 
        $subcat3=$_POST['subcat3']; 
        echo " cat=$cat <br> subcat=$subcat <br> subcat3= $subcat3 "; 
    ?> 

    <br>
    <br> 
    <a href=dd3.php>Reset and Try again</a> 
    <br>
    <br>
    <center><a href='plus2net.com'; rel="nofollow">PHP SQL HTML free tutorials and scripts</a></center> 
    </body> 
</html>
</div>
  • 写回答

2条回答 默认 最新

  • dongshuo9350 2014-09-24 21:23
    关注

    I pasted your PHP code into your original question.

    The PHP code supplied does not reference your database at all. It only receives three bits of data, called cat, and subcat, and subcat3, and then it attempts to print them onto the screen. However, that instruction is not written correctly.

    It should be:

    echo " cat=" .$cat. "<br> subcat=" .$subcat. "<br> subcat3=" .$subcat3;
    

    Better yet, I would construct a variable and output the variable:

    $out = 'cat: ' .$cat. '<br>';
    $out .= 'subcat: ' .$subcat. '<br>';
    $out .= 'subcat3: ' .$subcat3. '<br>';
    echo $out;
    

    In answer to your question:

    I Fixed It, Why Does It Not Work?

    1. The page outputs the HTML as specified until it reaches the PHP BEGIN tag: <?php

    2. It then reads the values posted into the webpage.

    3. It then outputs to the screen (via the echo command) the labels, plus their values.

    However, none of the values will print because the expected variable names are not sent to the dd3ck.php page!

    Notice in your form:

    <select name='Makerid'
    

    That is the only HTML tag with a name= attribute. The name= attribute creates the name by which the value is posted into the action= file.

    In the receiving PHP file (specified in the action= attribute), you can read that value like this:

    <?php
        $myVarName = $_POST['Makerid'];
        echo 'I received: ' . $myVarName. '<br>';
    

    Notice the label Makerid, in both the form and the (above) PHP snippet?

    The name= attribute on any HTML element inside a form becomes the name that you must use inside the $_POST['name_goes_here'] variable in the receiving PHP file.

    Therefore, the instruction $cat = $_POST['cat']; etc will never work because there is no HTML element with name="cat", or like <select name="subcat3">, or etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化