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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100