Jump to content

Recommended Posts

Hi all,

 

i have a question where i am stucked.

We want to build a database for our work. There will be a html and a php page. In the html page you will have a list of subjects. If you click on the subject it should post it to the php page where the result from mysql is shown. But i have a problem by building the variable. I will give a simple example.

 

the html page is --->

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />

<script type="text/javascript" language="javascript1.2">

function goster_gizle(x) {

          if ( document.getElementById(x).style.display == '' ) {

                document.getElementById(x).style.display = 'none'

          } else {

                document.getElementById(x).style.display = ''

          }

}

</script>

<style type="text/css">

.ust_menu{

    width: 150px;

    padding: 3px;

    border:1px solid #ccc;

}

.ust_menu a{

    text-decoration: none

}

.alt_menu {

    padding-left: 10px;

}

</style>

</head>

 

<body>

 

<form action="result.php" method="post">

 

 

 

<div class="ust_menu"><a href="javascript:goster_gizle('alt_menu_1')">VPN</a>

    <div class="alt_menu" id="alt_menu_1" style="display:none">

          <a href="javascript:goster_gizle('alt_menu_2')">Corina</a> <br>

          <div class="alt_menu" id="alt_menu_2" style="display:none">

          [b]<input type="submit" name="corina_account_request" value="corina account request">[/b]

          </div>

          <a href="javascript:goster_gizle('alt_menu_3')">Nira</a>    <br>

          <div class="alt_menu" id="alt_menu_3" style="display:none">

          Konu 2-2</div>

          <a href="javascript:goster_gizle('alt_menu_4')">RLA</a>  <br>

          <div class="alt_menu" id="alt_menu_4" style="display:none">

          Konu 3-3</div>

          <a href="javascript:goster_gizle('alt_menu_5')">Cisco</a>  <br>

          <div class="alt_menu" id="alt_menu_5" style="display:none">

          <a href="1.htm">Konu 4-4 </a></div>

          <a href="javascript:goster_gizle('alt_menu_6')">CheckPoint</a>

          <div class="alt_menu" id="alt_menu_6" style="display:none">

          <a href="1.htm">Konu 4-4</a></div>

    </div>

</div>

 

 

I marked the important thing here with green. If for example the subject "corina account request" is clicked it should post the value "corina_account_request" to the php page. The php page should get this and put it into the sql query.

 

here is the php page -->>>

 

<?php

 

@mysql_connect ("localhost","root","123*qwe123") or die ("nix sql") ;

 

@mysql_select_db ("kb") or die ("nix db") ;

 

$search = $_POST["name"]

 

?>

 

<table border="1" cellpadding="0" cellspacing="0">

  <tr>

    <td>Id</td>

    <td><?php $sql = mysql_query ("SELECT * FROM subjects where Subject = '$search' ") ;

    while ($liste = mysql_fetch_array($sql)) {

      echo "$liste[0]"; ?><?

 

}

 

mysql_free_result($sql);

 

echo mysql_error() ;

 

 

 

 

?></td>

  </tr>

 

 

but off course it doesn't work. The important thing for me is to get the value into this variable-->

 

$search = $_POST["name"]

 

it should basicly take the subject from the html page (there will be many) and put it into the query.

 

Can please someone help me.

 

thanks very much

Link to comment
https://forums.phpfreaks.com/topic/138564-solved-post-mysql/
Share on other sites

Why not just use GET variables?

 

Instead of the form/submit button:

<a href='result.php?name=corina_account_request'>Corina account request</a>

 

In the PHP file:

<?php

mysql_connect ("localhost","user","pass") or die (mysql_error()) ;

mysql_select_db ("kb") or die (mysql_error()) ;

$search = $_GET["name"]; // make sure to clean this variable - running the risk of SQL injection

?>

<table border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td>Id</td>
    <td><?php $sql = mysql_query ("SELECT * FROM subjects where Subject = '$search' ") ;
     while ($liste = mysql_fetch_array($sql)) {
      echo $liste[0];

}
mysql_free_result($sql);
?></td>
  </tr>

 

If you don't like my way, thats fine. You do have a missing semicolon though (in result.php):

$search = $_POST["name"]

 

 

Oh, and next time, don't forget the [ code ][/ code ] tags ;) It makes it easier on us to read your code.

Link to comment
https://forums.phpfreaks.com/topic/138564-solved-post-mysql/#findComment-724516
Share on other sites

Thanks for the quick replies...

 

Hi shadiadiph,

 

thanks for the suggestion, but as you said it would only post corina.

 

Hi revraz,

 

i am a beginner who is trying to learn from e-books and forums by himself. Thats why i wrote here

in hope for help. You should not criticise people but help if you are a member in such a forum like this.

This only demoralizes people who are searching for help. I think this is the right topic "PHP Help".

 

And Hi KingPhilip,

 

your suggestion was exactly what i needed, i tried it and it worked fine. Your the king :)

Thank you...

 

Problem Solved :)

Link to comment
https://forums.phpfreaks.com/topic/138564-solved-post-mysql/#findComment-724555
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.